home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / nethack.lha / nethack-3.1 / util / dgn_comp.l next >
Text File  |  1993-01-22  |  4KB  |  157 lines

  1. %{
  2. /*    SCCS Id: @(#)dgn_lex.c    3.1    92/10/23    */
  3. /*    Copyright (c) 1989 by Jean-Christophe Collet */
  4. /*    Copyright (c) 1990 by M. Stephenson         */
  5. /* NetHack may be freely redistributed.  See license for details. */
  6.  
  7. #define DGN_COMP
  8.  
  9. #include "config.h"
  10. #include "dgn_comp.h"
  11. #include "dgn_file.h"
  12.  
  13. long *FDECL(alloc, (unsigned int));
  14. /*
  15.  * Most of these don't exist in flex, yywrap is macro and
  16.  * yyunput is properly declared in flex.skel.
  17.  */
  18. #ifndef FLEX_SCANNER
  19. int FDECL (yyback, (int *, int));
  20. int NDECL (yylook);
  21. int NDECL (yyinput);
  22. int NDECL (yywrap);
  23. int NDECL (yylex);
  24.     /* Traditional lexes let yyunput() and yyoutput() default to int;
  25.      * newer ones may declare them as void since they don't return
  26.      * values.  For even more fun, the lex supplied as part of the
  27.      * newer unbundled compiler for SunOS 4.x adds the void declarations
  28.      * (under __STDC__ or _cplusplus ifdefs -- otherwise they remain
  29.      * int) while the bundled lex and the one with the older unbundled
  30.      * compiler do not.  To detect this, we need help from outside --
  31.      * sys/unix/Makefile.utl.
  32.      */
  33. # if defined(NeXT) || defined(SVR4)
  34. #  define VOIDYYPUT
  35. # endif
  36. # if !defined(VOIDYYPUT)
  37. #  if defined(POSIX_TYPES) && !defined(BOS) && !defined(HISX)
  38. #   define VOIDYYPUT
  39. #  endif
  40. # endif
  41. # if !defined(VOIDYYPUT) && defined(WEIRD_LEX)
  42. #  if defined(SUNOS4) && defined(__STDC__) && (WEIRD_LEX != 0) 
  43. #   define VOIDYYPUT
  44. #  endif
  45. # endif
  46. # ifdef VOIDYYPUT
  47. void FDECL (yyunput, (int));
  48. void FDECL (yyoutput, (int));
  49. # else
  50. int FDECL (yyunput, (int));
  51. int FDECL (yyoutput, (int));
  52. # endif
  53. #endif    /* FLEX_SCANNER */
  54.  
  55. void FDECL (init_yyin, (FILE *));
  56. void FDECL (init_yyout, (FILE *));
  57.  
  58. #ifdef MICRO
  59. #undef exit
  60. extern void FDECL(exit, (int));
  61. #endif
  62.  
  63. /* this doesn't always get put in dgn_comp.h
  64.  * (esp. when using older versions of bison)
  65.  */
  66.  
  67. extern YYSTYPE yylval;
  68.  
  69. int line_number = 1;
  70. /*
  71.  *    This is a hack required by Michael Hamel to get things
  72.  *    working on the Mac.
  73.  */
  74. #if defined(applec) && !defined(FLEX_SCANNER)
  75. #undef input
  76. #undef unput
  77. #define unput(c) { yytchar = (c); if (yytchar == 10) yylineno--; *yysptr++ = yytchar; }                  
  78. # ifndef YYNEWLINE
  79. # define YYNEWLINE 10
  80. # endif
  81.  
  82. char
  83. input() {    /* Under MPW \n is chr(13)! Compensate for this. */
  84.  
  85.     if (yysptr > yysbuf) return(*--yysptr);
  86.     else {
  87.         yytchar = getc(yyin);
  88.          if (yytchar == '\n') {
  89.             yylineno++;
  90.             return(YYNEWLINE);
  91.         }
  92.         if (yytchar == EOF) return(0);
  93.         else            return(yytchar);
  94.     }
  95. }
  96. #endif    /* applec && !FLEX_SCANNER */
  97.  
  98. %}
  99. %%
  100. DUNGEON        return(A_DUNGEON);
  101. up        { yylval.i=1; return(UP_OR_DOWN); }
  102. down        { yylval.i=0; return(UP_OR_DOWN); }
  103. ENTRY        return(ENTRY);
  104. stair        return(STAIR);
  105. no_up        return(NO_UP);
  106. no_down        return(NO_DOWN);
  107. portal        return(PORTAL);
  108. PROTOFILE    return(PROTOFILE);
  109. DESCRIPTION    return(DESCRIPTION);
  110. LEVELDESC    return(LEVELDESC);
  111. ALIGNMENT       return(ALIGNMENT);
  112. LEVALIGN        return(LEVALIGN);
  113. town        { yylval.i=TOWN ; return(DESCRIPTOR); }
  114. hellish        { yylval.i=HELLISH ; return(DESCRIPTOR); }
  115. mazelike    { yylval.i=MAZELIKE ; return(DESCRIPTOR); }
  116. roguelike    { yylval.i=ROGUELIKE ; return(DESCRIPTOR); }
  117. unaligned       { yylval.i=D_ALIGN_NONE ; return(DESCRIPTOR); }
  118. noalign         { yylval.i=D_ALIGN_NONE ; return(DESCRIPTOR); }
  119. lawful          { yylval.i=D_ALIGN_LAWFUL ; return(DESCRIPTOR); }
  120. neutral         { yylval.i=D_ALIGN_NEUTRAL ; return(DESCRIPTOR); }
  121. chaotic         { yylval.i=D_ALIGN_CHAOTIC ; return(DESCRIPTOR); }
  122. BRANCH        return(BRANCH);
  123. CHAINBRANCH    return(CHBRANCH);
  124. LEVEL        return(LEVEL);
  125. RNDLEVEL    return(RNDLEVEL);
  126. CHAINLEVEL    return(CHLEVEL);
  127. RNDCHLEVEL    return(RNDCHLEVEL);
  128. [-0-9]+        { yylval.i=atoi(yytext); return(INTEGER); }
  129. \"[^"]*\"    { yytext[yyleng-1] = 0; /* Discard the trailing \" */
  130.           yylval.str = (char *) alloc(strlen(yytext+1)+1);
  131.           strcpy(yylval.str, yytext+1); /* Discard the first \" */
  132.           return(STRING); }
  133. ^#.*\n        { line_number++; }
  134. \n        { line_number++; }
  135. [ \t]+        ;    /* skip trailing tabs & spaces */
  136. .        { return yytext[0]; }
  137. %%
  138.  
  139. /* routine to switch to another input file; needed for flex */
  140. void init_yyin( input_f )
  141. FILE *input_f;
  142. {
  143. #ifdef FLEX_SCANNER
  144.     if (yyin)
  145.         yyrestart(input_f);
  146.     else
  147. #endif
  148.         yyin = input_f;
  149. }
  150. /* analogous routine (for completeness) */
  151. void init_yyout( output_f )
  152. FILE *output_f;
  153. {
  154.     yyout = output_f;
  155. }
  156.  
  157.